package com.vader.boot.aspect;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author Vader
 * @date 2022/5/25
 **/
@Slf4j
public class JdkProxyDemo {

    interface Foo {
        void foo();
    }

    static final class Target implements Foo {

        @Override
        public void foo() {
            log.info("target_foo");
        }
    }

    public static void main(String[] args) {
        Target target = new Target();
        ClassLoader classLoader = JdkProxyDemo.class.getClassLoader();
        Foo foo = (Foo) Proxy.newProxyInstance(classLoader, new Class[]{Foo.class}, (proxy, method, args1) -> {
            log.info("JdkProxyDemo_proxy");
            return method.invoke(target,args1);
        });
        foo.foo();

    }
}
